<?php
/**
 * 文章分类
 */
include LIB_PATH . '/YAction.class.php';
class ArticletypeAction extends YAction {
	public function __construct() {
		parent::__construct();

		// 登录检测
		if(!$this->isLogin()) {
			echo '_error Access Timeout'; exit;
		}
	}
	
	public function index() {
		// 列表
		$data = D('Articletype')->getListByPage();
		$pageString = $data['pageString'];
		unset($data['pageString']);
		$this->assign('data', $data);
		$this->assign('pageString', $pageString);
		
		$this->display();
	}
	
	// 添加
	public function addArticletype() {
		
		$this->display();
	}
	public function doAddArticletype() {
		$data = array();
		$data['typename'] = y_getParam('typename');
		if(empty($data['typename'])) {
			$this->error('名称不能为空');
			exit;
		}
		
		D('Articletype')->addOne($data);
		
		$this->success('添加成功');
	}
	
	// 编辑
	public function editArticletype() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {exit;}
		
		$data = D('Articletype')->getOneByPk($id);
		$this->assign('data', $data);
		
		$this->display();
	}
	public function doEditArticletype() {
		$data = array();
		$id = y_getParam('pkid');
		if(!is_numeric($id)) {exit;}
		
		$data['typename'] = y_getParam('typename');
		D('Articletype')->updateOne('id='.$id, $data);
		
		$this->success('修改成功');
	}
	
	// 删除
	public function delArticletype() {
		$id = y_getParam('id', 'get');
		if(!is_numeric($id)) {exit;}
		
		D('Articletype')->deleteOne('id='.$id);
		
		$this->success('删除成功');
	}
}
